package org.goyo.main.domain.entity.sale;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.goyo.main.domain.entity.BaseObject;
import org.goyo.main.domain.entity.base.Customer;
import org.goyo.main.domain.entity.system.SysUser;
/**
 * 销售订单
 * 
 * @author chenchuan
 * 2014年11月12日
 */
@Entity
public class SaleOrder  extends BaseObject implements Serializable {

	private static final long serialVersionUID = 1L;
	//单据编号前缀
	public static final String BIZTYPE = "XS";
	/**
	 * 交货日期	
	 */
	@Column
	private String deliveryDate;
	/**
	 * 交货方式	
	 */
	@Column
	private String deliveryWay;
	/**
	 * 销售类型	
	 */
	@Column
	private String saleType;
	/**
	 * 累计付款金额
	 */
	@Column
	private BigDecimal sumReceiptAmount = BigDecimal.ZERO;
	
	/**
	 * 客户	
	 */
	@ManyToOne
	@JoinColumn(name="customerId")
	//@ExcelDataMapper(columNum = 2)
	private Customer customer;
	/**
	 * 销售员	
	 */
	@ManyToOne
	@JoinColumn(name="salePersonId")
	private SysUser salePerson;
	
	@OneToMany(fetch = FetchType.LAZY,cascade={CascadeType.ALL},mappedBy="saleOrder")
	private List<SaleOrderEntry> entrys = new ArrayList<SaleOrderEntry>();
	
	public String getDeliveryDate() {
		return deliveryDate;
	}
	public void setDeliveryDate(String deliveryDate) {
		this.deliveryDate = deliveryDate;
	}
	public String getDeliveryWay() {
		return deliveryWay;
	}
	public void setDeliveryWay(String deliveryWay) {
		this.deliveryWay = deliveryWay;
	}
	public String getSaleType() {
		return saleType;
	}
	public void setSaleType(String saleType) {
		this.saleType = saleType;
	}

	public List<SaleOrderEntry> getEntrys() {
		return entrys;
	}
	public void setEntrys(List<SaleOrderEntry> entrys) {
		if(entrys != null){
			for(SaleOrderEntry entry : entrys){
				entry.setSaleOrder(this);
			}
		}
		
		this.entrys = entrys;
	}
	public Customer getCustomer() {
		return customer;
	}
	public void setCustomer(Customer customer) {
		if(customer != null &&("".equals(customer.getUuid()) || customer.getUuid()==null))
			this.customer = null;
		else
			this.customer = customer;	
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public SysUser getSalePerson() {
		return salePerson;
	}
	public void setSalePerson(SysUser salePerson) {
		if(salePerson != null &&("".equals(salePerson.getUuid()) || salePerson.getUuid()==null))
			this.salePerson = null;
		else
			this.salePerson = salePerson;	
	}
	public BigDecimal getSumReceiptAmount() {
		return sumReceiptAmount;
	}
	public void setSumReceiptAmount(BigDecimal sumReceiptAmount) {
		this.sumReceiptAmount = sumReceiptAmount;
	}

	
}
